﻿using System.Linq;
using FacialClub.Models.Entities;
using FacialClub.Models.Interfaces;
namespace FacialClub.Models.Repositories
{
    /// <summary>
    /// Payment Method Repository
    /// </summary>
    public class PaymentMethodRepository : IPaymentMethodRepository
    {
        readonly FacialClubEntities _db = new FacialClubEntities();

        /// <summary>
        /// Get Payment Method Details by Title
        /// </summary>
        /// <param name="strQuery"></param>
        /// <returns></returns>
        public IQueryable<PaymentMethod> FindPaymentMethodByName(string strQuery)
        {
            return _db.PaymentMethods.Where(d => d.PaymentMethodName.Contains(strQuery));
        }

        /// <summary>
        /// Get All Payment Method
        /// </summary>
        /// <returns></returns>
        public IQueryable<PaymentMethod> FindAllPaymentMethod()
        {
            return _db.PaymentMethods;
        }

        /// <summary>
        /// Get Payment Method by Id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public PaymentMethod GetPaymentMethodById(int id)
        {
            return _db.PaymentMethods.SingleOrDefault(d => d.PaymentMethodId == id);
        }

        /// <summary>
        /// Add Payment Method in the Database
        /// </summary>
        /// <param name="paymentMethod"></param>
        public void Add(PaymentMethod paymentMethod)
        {
            _db.PaymentMethods.AddObject(paymentMethod);
        }

        /// <summary>
        /// Delete Payment Method from Database
        /// </summary>
        /// <param name="paymentMethod"></param>
        public void Delete(PaymentMethod paymentMethod)
        {
            _db.PaymentMethods.DeleteObject(paymentMethod);
        }

        /// <summary>
        /// Save Payment Method in the database
        /// </summary>
        public void Save()
        {
            _db.SaveChanges();
        }
    }
}